﻿/*-------------------------------------------------------------------------------------
 * Project Name             : Gems
 * Created By               : Mahesh vp
 * Created Date             : 06 nov 2012
 * Page Function            : 
 * -------------------------------------------------------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class SalesmanMaster : System.Web.UI.Page
{
    Encrypt encryptobj = new Encrypt();
    #region Page Event
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                LoadDropDown();
            }
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }
    #endregion

    #region Button Event
    protected void svebtn_Click(object sender, EventArgs e)
    {
        InsertUpdate();
    }
    #endregion

    #region User Defined Function

    private void LoadDropDown()
    {
        try
        {
            DataSet ds = DataAccessLayer.GetDataset("Gems_CommonUsertype");
            if (ds != null)
            {
                ddlUserType.DataSource = ds.Tables[0];
                ddlUserType.DataValueField = "UserType_ID";
                ddlUserType.DataTextField = "UserType";
                ddlUserType.DataBind();
            }

        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }


    private void InsertUpdate()
    {
        try
        {
            Hashtable hstbl1 = new Hashtable();
            hstbl1.Add("@UserName", txtUserName.Text);
            string encryptpwd = encryptobj.EncryptSring(txtPassowrd.Text);
            hstbl1.Add("@Password", encryptpwd);
            hstbl1.Add("@Email", txtName.Text);
            hstbl1.Add("@UserType_ID", ddlUserType.SelectedValue);
            hstbl1.Add("@MobileNo", txtMobileNo.Text);
            hstbl1.Add("@OfficeNo", txtOfficeNo.Text);
            hstbl1.Add("@DeliveryAddress", txtAddress.Text);
            hstbl1.Add("@PermanentAddres", txtAddress1.Text);
            hstbl1.Add("@Avatar", null);
            hstbl1.Add("@MaxCreditLimit", txtMaxCreditLimit.Text);
            hstbl1.Add("@Commission", txtCommission.Text);
            hstbl1.Add("@NoofDays", txtNoofDays.Text);
            hstbl1.Add("@chk_Discount", chk_Discount.Checked == true ? 1 : 0);
            hstbl1.Add("@DiscountAmt", txtDiscountaAmt.Text);
            hstbl1.Add("@chK_Movable", chK_Movable.Checked == true ? 1 : 0);

            Int64 intIdentity = DataAccessLayer.ReturnInsertDataCommand("GemsUser_InsertUpdate_SP", hstbl1);
            if (intIdentity > 0)
            {
                Response.Redirect("~/Master/StaffList.aspx?status=1", false);

            }
            else if (intIdentity == 0)
            {

                JSAlert.Show(Common.USERALREADYEXISTS);



            }
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }

    #endregion

}
